package basic;

import java.util.LinkedList;
import misc.BasicCountryOperations;

public class Country implements BasicCountryOperations{

	private String name = "";

	private LinkedList<League> leagues = null;

	public Country() {
		super();
		this.name = null;
		this.leagues = null;
	}

	public Country(String name) {
		super();
		this.name = name;
		this.leagues = new LinkedList<League>();
	}

	@Override
	public void addLeague(League league) {
		if (league != null){
			leagues.add(league);
		}

	}
	@Override
	public void removeLeague(String name, Country country) {
		if (name != null && country != null){
			for (int i = 0; i < leagues.size(); i++){
				if (name.equals(leagues.get(i).getName()) && country.equals(leagues.get(i).getCountry()))
					leagues.remove(i);
			}
		}
	}
	@Override
	public League createLeague(String name,Country country){
		if (name != null && country != null){
			return new League(name, country);
		}
		return null;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public LinkedList<League> getLeagues() {
		return leagues;
	}
	public League[] getLeaguesArray(){
		League[] leaguesArray = new League[leagues.size()];
		for (int i = 0; i < leagues.size(); i ++) {
			leaguesArray[i] = leagues.get(i);
		}
		return leaguesArray;
	}
	public League getLeague(String name){
		for(int i = 0; i < leagues.size(); i++){
			if (name.equals(leagues.get(i).getName()))
				return leagues.get(i);
		}
		return null;
	}

}
